package socdev.data;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class TeamUsersContainer extends UsersContainer {

	private User user;
	private Project project;
	
	public TeamUsersContainer(User user, Project project) {
		super();
		this.user = user;
		this.project = project;
	}
	
	@Override
	public void run() {
		try {

			JSONArray jsonArray = JSonDownloader.getData("http://socdev-dev1.appspot.com/api/group/users/", user.getNameValuePairs(project.getNameValuePairsKey(new ArrayList<NameValuePair>())));
			users = new HashMap<String, User>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				User user = User.createFromJson(jsonObject);
				users.put(user.getId(), user);

			}
		
		}catch (JSONException e) {
			e.printStackTrace();
		}
		this.handler.post(handlerRunnable);
		isUpdating = false;
	}
}
